package com.ys.web.user.login;

import com.ys.base.BaseDao;
import com.ys.web.user.info.RealEntity;
import org.apache.ibatis.annotations.*;

import java.util.Map;

public interface LoginDao extends BaseDao {

    /**
     * 功能:根据用户id查询信息
     *
     * @param uid 用户id
     * @return
     */
    LoginInfo infoById(@Param("uid") long uid);

    /**
     * 功能：根据unid查询登录信息
     *
     * @param unionId 微信unid
     * @return
     */
    LoginInfo infoByUnId(String unionId);

    /**
     * 功能：根据phone查询登录信息
     *
     * @param phone
     * @return
     */
    LoginInfo infoByPhone(String phone);

    ;

    /**
     * 功能：根据appleId查询登录信息
     *
     * @param appleId
     * @return
     */
    LoginInfo infoByApple(String appleId);

    /**
     * 功能：添加登录信息
     *
     * @param loginInfo 登录信息
     * @return
     */
    void addInfo(LoginInfo loginInfo);

    void initUserPrivacyConfig(LoginInfo loginInfo);

    /**
     * 功能:更新微信登录信息
     *
     * @param loginInfo 登录信息
     * @return
     */
    int updateInfoByWx(LoginInfo loginInfo);

    int updateInfoByPhone(LoginInfo loginInfo);

    int updateInfoByApple(LoginInfo loginInfo);

    /**
     * 添加黑名单用户信息
     *
     * @param uid 用户id
     * @return
     */
    int addBlack(@Param("uid") long uid);

    /**
     * 添加黑名单用户信息
     *
     * @param uid 用户id
     * @return
     */
    int cancelBlack(@Param("uid") long uid);

    @Delete("delete from user_wx where id=#{id}")
    int del(LoginInfo loginInfo);

    @Update("update user_wx set password=#{password},salt=#{salt} where id=#{id}")
    int updatePassWord(LoginInfo loginInfo);

    @Update("update user_wx set payPass=#{payPass} where id=#{id}")
    int updatePayPassWord(LoginInfo loginInfo);

    //    @Update("update user_wx set isCancel = 1 where id = #{uid}")
    //    @Update("update user_wx set isCancel = 1 where id = #{uid}")
    @Update("update user_wx set isBlack = 1 where id = #{uid}")
    void cancel(@Param("uid") Long uid);

    @Update("update user_wx set unionId = null, openId = null,realName = null , realIdCard = null , phone = CONCAT(phone,'_已注销','_',now()) , account_status = 1 where id = #{uid} ")
    void updateLocalInfoById(@Param("uid") Long uid);

    @Delete("delete from user_bank where user_id = #{uid}")
    void delUserBankInfo(@Param("uid") Long uid);

    @Delete("delete from user_bank_hjzf where user_id = #{uid}")
    void delUserBankHjzfInfo(@Param("uid") Long uid);

    @Select("select id uid,realName realName,realIdCard card from user_wx where realIdCard = #{idCard}  ")
    RealEntity getOpenAccountCountByCardNo(@Param("idCard") String idCard);

    @Select("select count(1) from user_real_update where uid =#{uid} ")
    int getUserRealInfoUpdateEntity(@Param("uid") String uid);

    @Select("select realName realName,realIdCard,phone card from user_wx where id = #{uid} ")
    Map<String, Object> getUserByUserId(String uid);

    @Insert("insert into user_real_update(uid,before_real_name,before_real_card,create_time) values (#{uid} ,#{realName},#{card},now())")
    void insertEntity(@Param("uid") String uid, @Param("realName") Object realName, @Param("card") Object card, @Param("phone")Object phone);

    @Update("update user_wx set realIdCard = #{idCard},realName = #{realName},phone=#{phone} where id = #{uid} ")
    int updateIdcard(@Param("uid") String uid, @Param("realName") String realName, @Param("idCard") String idCard, @Param("phone")String phone);

    LoginInfo LoginInfoLocal(@Param("value") String value, @Param("type") String type);

    @Update("update user_wx set ip = #{ip} where id = #{id} ")
    int updateUserIp(LoginInfo loginInfo);
}
